package com.googlecode.recycled.lang.jse.lang;

import com.google.common.base.Predicate;

import java.lang.reflect.Method;

public class MethodNamePredicate implements Predicate<Method> {

    protected String name;
    protected boolean equals;

    public MethodNamePredicate(String name, boolean equals) {
        this.name = name;
        this.equals = equals;
    }

    @Override
    public boolean apply(Method method) {
        if (method == null) {
            return !equals;
        }
        return !equals ^ method.getName().equals(name);
    }

    // PREDICATE FACTORIES

    public static MethodNamePredicate EQUAL(String name) {
        return new MethodNamePredicate(name, true);
    }

    public static MethodNamePredicate NON_EQUAL(String name) {
        return new MethodNamePredicate(name, false);
    }

}
